<template>
  <div>
    <button-v :to="'/my/collectionShop'" :text="'商品收藏'"></button-v>
    <button-v :to="'/my/collectionStore'" :text="'收藏店铺'"></button-v>
    <!--暂无数据  -->
    <div v-if="!favoriteList || favoriteList.length ==0">
      <div class="bgImg"></div>
    </div>
    <!--收藏数据不为空  -->
    <div class="store-container clearfix" v-else>
      <div class="storeItem" v-for="(storeInfo, index) in favoriteList" :key="index">
        <store-item :store-info="storeInfo"></store-item>
      </div>
      <div class="clear"></div>
      <div v-if="totalPage > 1">
        <w-paging :total="totalPage" @on-page="onPage"></w-paging>
      </div>
    </div>
  </div>
</template>

<script>
  import buttonV from './components/Button.vue'
  import storeItem from './components/StoreItem.vue'
  import { apiSelectFavoriteStoreAll } from 'js/api'
  import { mapGetters } from 'vuex'

  export default {
    data() {
      return {
        favoriteList: [],
        // 当前页
        currentPage: 1,
        // 一页显示
        showCount: 15,
        // 总页数
        totalPage: 0
      }
    },
    components: {
      buttonV,
      storeItem
    },
    computed: {
      ...mapGetters(['token'])
    },
    created() {
      this.getStore()
    },
    methods: {
      // 请求全部收藏店铺
      getStore() {
        apiSelectFavoriteStoreAll(this.token, this.currentPage, this.showCount).then((data) => {
          this.favoriteList = data.favoriteList
          // 获取总页数
          this.totalPage = data.totalPage
        })
      },
      onPage(pageIndex) {
        this.currentPage = pageIndex
        this.getStore()
      }
    }
  }
</script>

<style lang="scss" scoped>
  .bgImg {
    background-image: url(../../assets/nullIcon/icon_collection.png);
    margin: 50px auto auto;
    width: 310px;
    height: 270px;
    background-repeat: no-repeat;
    text-align: center;
    background-size: contain;
    background-position: 50% 50%;
  }
  .store-container {
    background-color: #fff;
    padding: 20px 50px;
    margin-top: 10px;
    .storeItem {
      float: left;
      margin-right: 20px;
      margin-bottom: 20px;
      &:nth-child(5n+5) {
        margin-right: 0;
      }
    }
    .clear {
      clear: both;
    }
  }
</style>